package Clothing.serviceImpl.login;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import Clothing.bean.request.login.LoginRequest;
import Clothing.bean.respose.login.LoginResponse;
import Clothing.dao.UserDao;
import Clothing.entity.UserEntity;
import Clothing.service.login.LoginService;

@Service("loginService")
public class LoginServiceImpl implements LoginService {
    @Autowired
    private UserDao userDao;

    public int login(LoginRequest request, LoginResponse response) {
        String username = request.getUsername();
        String password = request.getPassword();
        Map<String, Object> map = new HashMap<String, Object>();
        if (StringUtils.isBlank(password) || StringUtils.isBlank(username)) {
            return 1;
        }
        map.put("userName", username);
        map.put("password", password);
        UserEntity userEntity = userDao.getUser(map);
        if (userEntity == null) {
            return 1;
        }
        response.setUserName(userEntity.getUserName());
        response.setRoleId(userEntity.getUserType());
        response.setUserId(String.valueOf(userEntity.getUserId()));
        return 0;
    }

}
